/**
 * Created by zeopean on 2015/9/16.
 */
$(function(){
    /** 初始化ajax */
    jQuery.ajaxSetup({
        case:false,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $('.save').bind('click' , function(){
        /** 获取数据 */
        var realname = $('input[name=realname]').val();
        var user_id = $('input[name=user_id]').val();
        var province = $('input[name=province]').val();
        var city = $('input[name=city]').val();
        var wechat = $('input[name=wechat]').val();
        var weibo = $('input[name=weibo]').val();
        var maimai = $('input[name=maimai]').val();
        var photo_id = $('#photo_id').val();
        var edu_school = $('input[name=edu_school]').val();
        var position    = $('input[name=position]').val();
        var user_desc   = $('textarea').val();

        $.ajax({
            type:"post",
            url:editUserInfoByAdmin,
            dataType:"json",
            data:{
                'realname':realname,
                'user_id':user_id,
                'province':province,
                'city':city,
                'wechat':wechat,
                'weibo':weibo,
                'maimai':maimai,
                'photo_id':photo_id,
                'edu_school':edu_school,
                'position':position,
                'user_desc':user_desc
            },
            success:function(obj){
                if(obj.level === "success"){
                    window.location.href=Home;
                }
            },
            error:function(obj){
                var datajson = obj.responseJSON;
                noty({text:datajson.message,type:datajson.level,timeout:800});
            }
        });
    });

    /** 清楚所有表单 */
    $('.yes').bind('click' , function(){
        $(':input').val('');
    });

    /** 删除创业者 */
    $('.del').bind('click' , function(){
        var userId  =   $(this).attr('data');
        var tmp     =   $(this);
        $.ajax({
            type: "get",
            url: DelAdminById,
            dataType: "json",
            data: {
                'userId'    : userId
            },
            success: function (obj) {
                if (obj.level === "success") {
                    noty({text:obj.message,type:obj.level,timeout:500});
                    tmp.parents('tr').hide();
                }
            },
            error: function (obj){
                var datajson = obj.responseJSON;
                noty({text:datajson.message,type:datajson.level,timeout:1000});
            }
        });
    });
    /** end */



});